define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'goods_stock/index' + location.search,
                    add_url: 'goods_stock/add',
                    edit_url: 'goods_stock/edit',
                    //del_url: 'goods_stock/del',
                    multi_url: 'goods_stock/multi',
                    import_url: 'goods_stock/import',
                    table: 'goods_stock',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {field: 'goods.name', title: __('Goods.name'), operate: 'LIKE'},
                        {field: 'goodsspecone.name', title: __('Goodsspecone.name'), operate: 'LIKE'},
                        {field: 'goodsspectwo.name', title: __('Goodsspectwo.name'), operate: 'LIKE'},
                        {field: 'num', title: __('Num')},
                        {field: 'use_integral', title: __('Use_integral')},
                        {field: 'cost_price', title: __('成本价格')},
                        {field: 'vip_price', title: __('vip价格'), operate: false},

                        {field: 'price', title: __('销售价格')},
                        {field: 'new_price', title: __('New_price')},
                        {field: 'now_price', title: __('Now_price')},
                        {field: 'zhekou_price', title: __('Zhekou_price')},
                        {field: 'image', title: __('Image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,

                            buttons: [

                                    {
                                        name: 'detail',
                                        title: __('库存修改记录'),
                                        classname: 'btn btn-xs btn-primary btn-dialog',
                                        icon: 'fa fa-list',
                                        url: 'goods_stock/updatestock'
                                    }
                                ] 
                        }
                    ]
                ],
                search:false,
                showColumns: false,
                showToggle: false,
                showExport: false,
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});